package com.example.ymm.modules1.service.impl.hl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.hl.yw.YwGroup;
import com.example.ymm.modules1.mapper.hl.YwGroupMapper;
import com.example.ymm.modules1.query.hl.YwGroupQueryCriteria;
import com.example.ymm.modules1.service.hl.YwGroupService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@DS("slave2")
public class YwGroupServiceImpl extends BaseServiceImpl<YwGroupMapper, YwGroup> implements YwGroupService {

    @Override
    public TableList<YwGroup> list(YwGroupQueryCriteria criteria, YmPageDto pageDto) {
        IPage<YwGroup> page = new Page<YwGroup>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(YwGroup.class, criteria);
//        predicate.orderByDesc("create_time");
        baseMapper.selectPage(page, predicate);
        TableList<YwGroup> tableList=new TableList(page);
        return tableList;
    }

    public List<YwGroup> queryAll(YwGroupQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(YwGroup.class, criteria);
//        predicate.orderByDesc("create_time");
        List<YwGroup> result =baseMapper.selectList(predicate);
        return result;
    }
}
